﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace StarForce {
    public abstract class CardPile :MonoBehaviour, ICardPile {
        /// <summary>
        /// 所有卡牌的队列
        /// </summary>
        public List<Card> CardList { get; private set; }
        event Action<Card[]> onPileChange = hand => { };
        /// <summary>
        /// 在添加或移除卡牌时调用的回调函数
        /// </summary>
        public Action<Card[]> OnPileChange { get => onPileChange; set => onPileChange = value; }
        protected virtual void Awake() {
            CardList = new List<Card>();
        }
        
        public virtual void AddCard(Card card) {
            if (card == null) {
                throw new ArgumentNullException("Card Cant not be null!");
            }
            CardList.Add(card);
            NotifyPileChange();
        }

        public virtual void RemoveCard(Card card) {
            if (card == null) {
                throw new ArgumentNullException("Card Cant not be null!");
            }

            CardList.Remove(card);
            NotifyPileChange();
        }
        
        public void NotifyPileChange() => onPileChange?.Invoke(CardList.ToArray());

    }
}
